package com.yzt.minemodule.wallet;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yzt.zhuju.base.BaseActivity;
import com.yzt.zhuju.constants.IntentConstant;
import com.yzt.zhuju.network.entity.mine.wallet.WalletDetialList;
import com.yzt.minemodule.R;
import com.yzt.minemodule.wallet.adapter.WalletDetailInfoAdapter;
import com.yzt.minemodule.wallet.entry.WalletDetailInfoEntry;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能：收支详情
 */
public class WalletDetailInfoActivity extends BaseActivity {

    private static final String KEY_WALLET_DETAIL = "wallet_detail";

    private WalletDetailInfoAdapter mWalletDetailInfoAdapter;

    private List<WalletDetailInfoEntry> mList;

    private WalletDetialList mWalletDetail;

    public static void start(Activity activity, int type, WalletDetialList detail, int resultCode) {
        Intent intent = new Intent(activity, WalletDetailInfoActivity.class);
        intent.putExtra(IntentConstant.INTENT_ID, type);
        intent.putExtra(KEY_WALLET_DETAIL, detail);
        activity.startActivityForResult(intent, resultCode);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_wallet_detail_info;
    }

    @Override
    public void installViews() {
        mWalletDetail = (WalletDetialList) getIntent().getSerializableExtra(KEY_WALLET_DETAIL);

        mTitleBar.setTitle(R.string.str_detail);

        mList = new ArrayList<>();
        RecyclerView mListRv = findViewById(R.id.list_rv);
        mWalletDetailInfoAdapter = new WalletDetailInfoAdapter();
        mListRv.setLayoutManager(new LinearLayoutManager(mActivity));
        mListRv.setAdapter(mWalletDetailInfoAdapter);

        initData();
    }

    public void initData() {
        if (mWalletDetail == null) {
            return;
        }
        boolean amount = TextUtils.equals(mWalletDetail.getType(), "income");
        mList.add(new WalletDetailInfoEntry(amount ? getString(R.string.income_time) : getString(R.string.pay_time),
                mWalletDetail.getRecordDay() + "  " + mWalletDetail.getRecordTime()));
        mList.add(new WalletDetailInfoEntry(amount ? getString(R.string.income_project) : getString(R.string.pay_project),
                mWalletDetail.getItem()));
        mList.add(new WalletDetailInfoEntry(amount ? getString(R.string.consumer) : getString(R.string.acquirer),
                mWalletDetail.getTargetUsername()));
        mList.add(new WalletDetailInfoEntry(amount ? getString(R.string.income_money) : getString(R.string.pay_money),
                mWalletDetail.getAmount()));
        mWalletDetailInfoAdapter.addData(mList);
    }
}
